package AI;

import java.util.Random;
import things.Player;
import things.World;

/*
 * Ben McCrary
 * Spring 2011
 */
public class AI {

    public World w;
    public Player p;
    public static roomInfo[][] info;

    /**
     *
     * @param w World that the AI should live in
     */
    public AI(World w) {
        this.w = w;
        p = w.p;
    }

    /**
     * The main run method.
     */
    public void run() {
        System.out.println("creating new info");
        info = new roomInfo[4][4];
        for (int i = 0; i < 4; i++) {
            for (int j = 0; j < 4; j++) {
                info[i][j] = new roomInfo();
            }
        }
        System.out.println("info created");
        while (!p.foundGold()) {
            int yLoc = p.xLoc;
            int xLoc = p.yLoc;
            //System.out.println("Setting info[" + xLoc + "][" + yLoc + "] to true");
            info[xLoc][yLoc].isExplored = true;

            randomMove();
            for (int i = 0; i < 4; i++) {
                for (int j = 0; j < 4; j++) {
                    System.out.print(info[i][j].pitChance + " ");
                }
                System.out.println();
            }
            System.out.println();
        }
        System.out.println("Found me gold!");
    }

    /**
     * Chooses a random direction to move in.
     */
    public void randomMove() {
        Random r = new Random();
        int ran = r.nextInt(4);
        if (ran == 0) {
            p.moveUp();
        } else if (ran == 1) {
            p.moveDown();
        } else if (ran == 2) {
            p.moveLeft();
        } else {
            p.moveRight();
        }
    }
}
